package com.braveman.im.ui.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.braveman.im.R;
import com.braveman.im.bean.GetFriendsInfoByIMid;
import com.braveman.im.bean.PersonInfoDetailsBean;
import com.braveman.im.bean.PersonalDataBaen;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.vondear.rxtools.RxBarTool;

import retrofit2.Call;
import retrofit2.Response;

/**
 * 作者 昊昊.
 * 年份 2017/10/23.
 * 时间 18:33.
 * 项目名称 ZhengQiApp.
 */

/**
 * 个人资料
 */
public class PersonalDataActivity extends BaseActivity {
    private TextView numBer;
    private TextView naMe;
    private TextView phoneNumber;
    private TextView weiXin;
    private TextView QQ;
    private TextView eMail;
    private TextView birThday;
    private TextView nativePlace;
    private TextView exPectation;
    private TextView companyName;
    private TextView duTy;
    private TextView companyPhone;
    private TextView indusTry;
    private TextView addRess;
    private PersonalDataBaen pb;
    private String friendId;

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("个人资料").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(PersonalDataActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_personal_data;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        friendId = callIntent.getStringExtra("friendId");
    }

    @Override
    protected void initChildView() {
        numBer = (TextView) findViewById(R.id.tx_activity_number);
        naMe = (TextView) findViewById(R.id.tx_activity_name);
        phoneNumber = (TextView) findViewById(R.id.tx_activity_phone_number);
        weiXin = (TextView) findViewById(R.id.tx_activity_weixin);
        QQ = (TextView) findViewById(R.id.tx_activity_qq);
        eMail = (TextView) findViewById(R.id.tx_activity_email);
        birThday = (TextView) findViewById(R.id.tx_activity_birthday);
        nativePlace = (TextView) findViewById(R.id.tx_activity_native_place);
        exPectation = (TextView) findViewById(R.id.tx_activity_expectation);
        companyName = (TextView) findViewById(R.id.tx_activity_company);
        duTy = (TextView) findViewById(R.id.tx_activity_duty);
        companyPhone = (TextView) findViewById(R.id.tx_activity_company_phone);
        indusTry = (TextView) findViewById(R.id.tx_activity_profession);
        addRess = (TextView) findViewById(R.id.tx_activity_address);
    }

    @Override
    protected void initChildData() {
        if (TextUtils.isEmpty(friendId)) {
            doMineInfo();
            return;
        }
        //好友信息
        ApiManager.getApi().getPersonInfoDetailsMore(friendId).enqueue(new NetCallBack<PersonInfoDetailsBean>() {
            @Override
            protected void onSuccess(Call<PersonInfoDetailsBean> call, Response<PersonInfoDetailsBean> response) {
                if (response!=null){
                    PersonInfoDetailsBean pb = response.body();
                    naMe.setText(pb.friendName);
                    numBer.setText(pb.friendSn);
                    phoneNumber.setText(pb.friendPhone);
                    weiXin.setText(pb.wechatId.toString());
                    QQ.setText(pb.qq.toString());
                    eMail.setText(pb.email.toString());
                    birThday.setText(pb.birth.toString());
                    nativePlace.setText(pb.birthplaceId.toString());
                    exPectation.setText(pb.lookForwardToMeet.toString());
                    companyName.setText(pb.corpName.toString());
                    duTy.setText(pb.corpJob.toString());
                    companyPhone.setText(pb.corpPhone.toString());
                    indusTry.setText(pb.corpIndustryName.toString());
                    addRess.setText(pb.corpDetailedAddress.toString());
                }
            }
        });

    }

    //个人信息
    private void doMineInfo() {
        pb = new PersonalDataBaen();//
        ApiManager.getApi().getPersonalData().enqueue(new NetCallBack<PersonalDataBaen>() {
            @Override
            protected void onSuccess(Call<PersonalDataBaen> call, Response<PersonalDataBaen> response) {
                pb = response.body();
                if (pb != null) {
                    naMe.setText(pb.name.toString());
                    numBer.setText(pb.sn.toString());
                    phoneNumber.setText(pb.mobile.toString());
                    weiXin.setText(pb.wechatId.toString());
                    QQ.setText(pb.qq.toString());
                    eMail.setText(pb.email.toString());
                    birThday.setText(pb.birth.toString());
                    nativePlace.setText(pb.birthplaceId.toString());
                    exPectation.setText(pb.lookForwardToMeet.toString());
                    companyName.setText(pb.corpName.toString());
                    duTy.setText(pb.corpJob.toString());
                    companyPhone.setText(pb.corpPhone.toString());
                    indusTry.setText(pb.corpIndustryName.toString());
                    addRess.setText(pb.corpDetailedAddress.toString());

                }
            }
        });
    }

    @Override
    protected void setChildViewListener() {

    }
}
